package com.meitianhui.convenitenbuy.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.meitianhui.convenitenbuy.R;
import com.meitianhui.convenitenbuy.util.GlideUtils;

/**
 * Created by Administrator on 2017/11/15.
 */

public class AdDialog extends Dialog implements View.OnClickListener {
    private Context context;
    private ChooseStoreDialog dialog = null;
    private DialogClick dialogClick;
    private ImageView mIvPic;
    private TextView mTvClose;
    private TextView mTvContent;

    /**
     * @param context
     * @param layoutMode  0 :广告布局  1：签到布局
     * @param dialogClick
     */
    public AdDialog(Context context, int layoutMode, DialogClick dialogClick) {
        super(context);
        this.context = context;
        this.dialogClick = dialogClick;
        dialog = new ChooseStoreDialog(context, R.style.dialog_with_alpha);
        if (layoutMode == 0) {
            dialog.setContentView(R.layout.dialog_ad);
        } else {
            dialog.setContentView(R.layout.dialog_sign);
        }
        dialog.setCanceledOnTouchOutside(true);
        initView(dialog);
        dialog.show();

    }

    /**
     * 布局绑定
     *
     * @param dialog
     */
    private void initView(ChooseStoreDialog dialog) {
        mIvPic = (ImageView) dialog.findViewById(R.id.iv_pic);
        mIvPic.setOnClickListener(this);
        mTvClose = (TextView) dialog.findViewById(R.id.tv_close);
        mTvClose.setOnClickListener(this);
        mTvContent = (TextView) dialog.findViewById(R.id.tv_content);
    }

    public void setImagePath(String path) {
        GlideUtils.setRectImage(context, path, R.mipmap.icon_home_default_recommend_goods, R.mipmap.icon_home_default_recommend_goods, mIvPic);
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.tv_close:    //关闭
                stopProgressDialog();
                break;
            case R.id.iv_pic:  //图片点击
                if (dialogClick != null) {
                    dialogClick.imageClick();
                }
                break;
        }
    }

    public void setTextContext(String content) {
        mTvContent.setVisibility(View.VISIBLE);
        mTvContent.setText(content);
    }


    public void stopProgressDialog() {
        if (dialog != null && dialog.isShowing()) {
            dialog.dismiss();
            dialog = null;
        }
    }

    public void setOnClickListener(DialogClick l) {
        this.dialogClick = l;
    }

    public interface DialogClick {

        void imageClick();


    }
}